/*    */ package com.zimbra.cs.service.account;
/*    */ 
/*    */ import com.zimbra.common.account.SignatureUtil;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AccountConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.SoapFaultException;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Signature;
/*    */ import com.zimbra.soap.DocumentHandler;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CreateSignature
/*    */   extends DocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException, SoapFaultException
/*    */   {
/* 38 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 39 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 41 */     if (!canModifyOptions(zsc, account)) {
/* 42 */       throw ServiceException.PERM_DENIED("can not modify options");
/*    */     }
/* 44 */     Element eReqSignature = request.getElement("signature");
/* 45 */     String name = eReqSignature.getAttribute("name");
/* 46 */     String id = eReqSignature.getAttribute("id", null);
/*    */     
/* 48 */     List<Element> contents = eReqSignature.listElements("content");
/* 49 */     Map<String, Object> attrs = new HashMap();
/* 50 */     for (Element eContent : contents) {
/* 51 */       String type = eContent.getAttribute("type");
/* 52 */       String attr = SignatureUtil.mimeTypeToAttrName(type);
/* 53 */       if (attr == null)
/* 54 */         throw ServiceException.INVALID_REQUEST("invalid type " + type, null);
/* 55 */       if (attrs.get(attr) != null) {
/* 56 */         throw ServiceException.INVALID_REQUEST("only one " + type + " content is allowed", null);
/*    */       }
/* 58 */       String content = eContent.getText();
/* 59 */       if (!StringUtil.isNullOrEmpty(content)) {
/* 60 */         attrs.put(attr, content);
/*    */       }
/*    */     }
/* 63 */     if (id != null) {
/* 64 */       attrs.put("zimbraSignatureId", id);
/*    */     }
/* 66 */     Element eContactId = eReqSignature.getOptionalElement("cid");
/* 67 */     if (eContactId != null) {
/* 68 */       attrs.put("zimbraPrefMailSignatureContactId", eContactId.getText());
/*    */     }
/* 70 */     Signature signature = Provisioning.getInstance().createSignature(account, name, attrs);
/*    */     
/* 72 */     Element response = zsc.createElement(AccountConstants.CREATE_SIGNATURE_RESPONSE);
/* 73 */     Element eRespSignature = response.addElement("signature");
/* 74 */     eRespSignature.addAttribute("id", signature.getId());
/* 75 */     eRespSignature.addAttribute("name", signature.getName());
/* 76 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/CreateSignature.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */